<?php

declare(strict_types=1);
/**
 * This file is part of MineAdmin.
 *
 * @link     https://www.mineadmin.com
 * @document https://doc.mineadmin.com
 * @contact  root@imoi.cn
 * @license  https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
 */

namespace App\Model;

use Hyperf\Database\Model\Relations\BelongsTo;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\DbConnection\Model\Model;

/**
 * App\Distributor
 *
 * @property int $id
 * @property int $distributor_id 业主id
 * @property string $label 分组名称
 */
class StationClass extends Model
{
    public bool $timestamps = true;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'station_class';


    protected array $fillable = [
        'label','distributor_id'
    ];

    protected array $casts = [
        'created_at'=>'datetime',
        'updated_at'=>'datetime'
    ];

    /**经销商
     * @return BelongsTo
     */
    public function distributor():BelongsTo{
        return $this->belongsTo(Distributors::class,'distributor_id','id');
    }

    /**电站
     * @return HasMany
     */
    public function station():HasMany{
        return $this->hasMany(Station::class,'class_id','id');
    }

    public function children():HasMany{
        return $this->hasMany(Station::class,'class_id','id')
            ->select('id', 'class_id', 'name as label');
    }
}
